/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.imgs;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

/**
 * <p>Project: javaseapp - Img7
 * <p>Powered by webrx On 2021-08-16 08:46:51
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Img8 {
    public static void main(String[] args) throws IOException {
        Random rand = new Random();
        int w = 800, h = 800, t = 2;
        BufferedImage i = new BufferedImage(w, h, t);
        var g = i.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        //实心填充ORANGE的矩形，相当于设置图像的背景
        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, w, h);

        g.setColor(getRandColorAlpha());
        g.drawLine(0, 0, w, h);

        g.setStroke(new BasicStroke(3));
        g.setColor(Color.WHITE);
        for (int n = 0; n < 800; n++) {
            int x = n;
            n += 18;
            g.drawLine(x, 400, x + 5, 400);
        }

        //空心，没有填充的椭圆
        g.drawOval(10, 20, 30, 30);

        //填充矩形
        g.drawRect(50, 50, 50, 50);

        g.drawArc(100, 100, 100, 100, 0, 180);


        g.dispose();
        ImageIO.write(i, "png", new File("c:/ok.png"));

        Runtime run = Runtime.getRuntime();
        run.exec("cmd /k start c:/ok.png");
    }

    public static Color getRandColor() {
        Random rand = new Random();
        return new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
    }

    public static Color getRandColorAlpha() {
        Random rand = new Random();
        return new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
    }
}
